package com.zyong.design.pattern.memento.case2;

/**
 * @program: zyong-design-pattern
 * @ClassName: Client
 * @author: zyong
 * @create: 2024-05-12 23:04
 */
public class Client {
    public static void main(String[] args) {
        TextDocument document = new TextDocument();
        Caretaker caretaker = new Caretaker();

        System.out.println("初始内容:" + document.getContent());

        document.setContent("第一次编辑");
        caretaker.addMemento(document.saveToMemento());
        System.out.println("编辑后内容:" + document.getContent());

        document.setContent("第二次编辑");
        System.out.println("再次编辑后内容:" + document.getContent());

        // 使用备忘录恢复状态
        if (caretaker.hasSavedStates()) {
            document.restoreFromMemento(caretaker.getMemento());
            System.out.println("撤销后内容:" + document.getContent());
        }

        // 尝试再次撤销，但没有更多的保存状态了
        if (caretaker.hasSavedStates()) {
            document.restoreFromMemento(caretaker.getMemento());
            System.out.println("再次撤销后内容:" + document.getContent());
        } else {
            System.out.println("没有更多的状态可以撤销了");
        }
    }
}
